package com.ymatou.iapi.exp.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.ymatou.iapi.exp.parameter.CalcOrderEvalCoinBean;
import com.ymatou.iapi.exp.service.CalcOrderEvalCoinCall;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.enums.LogisticsTypeEnum;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.ExpCallService;
import com.ymttest.database.sqlwapper.ExpWapper;
/**
*计算评价订单可获得的金币数
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CalcOrderEvalCoin{
	private static CalcOrderEvalCoinBean calcorderevalcoinBean;
	private static CalcOrderEvalCoinCall calcorderevalcoinCall;
	private static ExpWapper ExpWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("计算评价订单可获得的金币数");
	}

	@Before
	public void caseUp() {
		calcorderevalcoinBean=new CalcOrderEvalCoinBean();
		calcorderevalcoinCall=new CalcOrderEvalCoinCall();
		ExpWapper=new ExpWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(calcorderevalcoinCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CalcOrderEvalCoin_001() {
		Logger.start(true,"计算评价订单可获得的金币数成功");
		try {
			Long OrderId=1l;
			int num=1;
			ExpCallService.resetOrderCNum(OrderId, num);
			List<String> orderIdList=new ArrayList<>();
			orderIdList.add(OrderId.toString());
			calcorderevalcoinBean.setOrderIdList(orderIdList);
			calcorderevalcoinBean.setShowDetail(false);
			calcorderevalcoinCall.setData(calcorderevalcoinBean);
			calcorderevalcoinCall.callService();			
			
			Logger.verifyEquals("0", calcorderevalcoinCall.getString("BCode"), "验证BCode");
			JsonObject result = calcorderevalcoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals(num*ExpCallService.EvalCoin, result.get("coin").getAsInt(), "验证coin");
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CalcOrderEvalCoin_002() {
		Logger.start(true,"计算评价订单可获得的金币数多条记录");
		try {
			Long OrderId=1l;
			int num=2;
			ExpCallService.resetOrderCNum(OrderId, num);
			List<String> orderIdList=new ArrayList<>();
			orderIdList.add(OrderId.toString());
			calcorderevalcoinBean.setOrderIdList(orderIdList);
			calcorderevalcoinBean.setShowDetail(false);
			calcorderevalcoinCall.setData(calcorderevalcoinBean);
			calcorderevalcoinCall.callService();			
			Logger.verifyEquals("0", calcorderevalcoinCall.getString("BCode"), "验证BCode");
			JsonObject result = calcorderevalcoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals(num*ExpCallService.EvalCoin, result.get("coin").getAsInt(), "验证coin");
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CalcOrderEvalCoin_003() {
		Logger.start(true,"showDetail为true显示详细");
		try {
			Long OrderId=1l;
			ExpCallService.resetOrderCNum(OrderId, 1);
			List<String> orderIdList=new ArrayList<>();
			orderIdList.add(OrderId.toString());
			calcorderevalcoinBean.setOrderIdList(orderIdList);
			calcorderevalcoinBean.setShowDetail(true);
			calcorderevalcoinCall.setData(calcorderevalcoinBean);
			calcorderevalcoinCall.callService();			
			Logger.verifyEquals("0", calcorderevalcoinCall.getString("BCode"), "验证BCode");
			JsonObject result = calcorderevalcoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals(ExpCallService.EvalCoin, result.get("coin").getAsInt(), "验证coin");
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			JsonArray orderCoinList = result.get("orderCoinList").getAsJsonArray();
			orderCoinList.forEach(oc->{
				int orderId = oc.getAsJsonObject().get("orderId").getAsInt();
				Logger.verifyIsContains(orderId, calcorderevalcoinBean.getOrderIdList().toString(), "返回数据包含");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CalcOrderEvalCoin_004() {
		Logger.start(true,"不输入orderIdList失败");
		try {
			calcorderevalcoinBean.equals(true);
			calcorderevalcoinCall.setData(calcorderevalcoinBean);
			calcorderevalcoinCall.callService();			
			Logger.verifyEquals("2", calcorderevalcoinCall.getString("Code"), "验证Code");
			JsonObject result = calcorderevalcoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("false", result.get("success").toString(), "验证success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CalcOrderEvalCoin_005() {
		Logger.start(true,"计算多个订单评价订单可获得的金币数多条记录");
		try {
			ExpCallService.resetOrderCNum(6001l, 2);
			ExpCallService.resetOrderCNum(6002l, 3);
			List<String> orderIdList=new ArrayList<>();
			orderIdList.add("6001");
			orderIdList.add("6002");
			calcorderevalcoinBean.setOrderIdList(orderIdList);
			calcorderevalcoinBean.setShowDetail(true);
			calcorderevalcoinCall.setData(calcorderevalcoinBean);
			calcorderevalcoinCall.callService();			
			Logger.verifyEquals("0", calcorderevalcoinCall.getString("BCode"), "验证BCode");
			JsonObject result = calcorderevalcoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			//（2+3） *5
			Logger.verifyEquals(ExpCallService.EvalCoin*5, result.get("coin").getAsInt(), "验证coin");
			JsonArray orderCoinList = result.get("orderCoinList").getAsJsonArray();
			orderCoinList.forEach(oc->{
				int orderId = oc.getAsJsonObject().get("orderId").getAsInt();
				Logger.verifyIsContains(orderId, calcorderevalcoinBean.getOrderIdList().toString(), "返回数据包含");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}